//终端监控列表 0

//(function(){
define(function(require,exports,module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
	var wind_async=require('ddf_wind_async');
		
	var base=require('component-base');
		
	var history=require('component-history');
	
	require('component-page');
	
    var pageIndex=0;

    var tips_index=0;

    var terminalId="";
    

/**
 * 查询终端列表
 */
//function loadTerminalList() {
   exports.init=function(m){
	   history.addHis(this,arguments);//增加历史
	window.$ddf_terminal = m;
	terminalId="";
	pageIndex=0;
	var htmlStr="";

	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">设备监控</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';

	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">终端编码：</label><div class="controls"><input class="span8 m-wrap" type="text" id="terminalId"/></div></div></div>';
	htmlStr += '<div class="span6"><div class="control-group"></div></div>';
	htmlStr += '</div>   ';

	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_terminal.searchTerminal()">搜索</button>';
	htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_terminal.resetSearchParams()">重置</button>';
	htmlStr += '</div>        ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>终端列表</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr>';
	htmlStr += '<th>序号</th>';
	htmlStr += '<th>终端编码</th>';
	htmlStr += '<th>商户名称</th>';
	htmlStr += '<th>生产厂家名称</th>';
	htmlStr += '<th>当前版本号</th>';
	htmlStr += '<th>是否有效</th>';
	htmlStr += '<th>状态</th>';
	htmlStr += '</tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody id="terminalList">';
	htmlStr += '</tbody>';
	htmlStr += '</table>';
	htmlStr += '<div  id="footPageDiv'+pageIndex+'">';

	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';

//	$("#content0").css("display", "block");
	showDiv("content0");

	$("#content0").html(htmlStr);


	getQueryTerminalList(1,10,terminalId);



}

/**
 * 查询终端列表
 */
function getQueryTerminalList(pageNumber,pageSize,_terminalId){
	
	var params={
			"page.pageNumber":pageNumber,
			"terminalId":terminalId,
			"page.pageSize" : pageSize
	        };
	

	base.showLoading();
	
    eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.terminal.queryTerminal,params));
		
		getQueryTerminalListCallBack(data);
		
	}))().start();
//	DDF_AsyncRequest("POST",ddf.terminal.queryTerminal,params,'$ddf_terminal.getQueryTerminalListCallBack(data)');
	
}

/**
 * 查询会员列表_回调函数
 */
function getQueryTerminalListCallBack(data){
	
	if(data["code"]==1){
		var htmlStr = "";

		for (var i = 0; i < data["terminalListData"].length; i++) {

			htmlStr += '<tr>';
			htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
			htmlStr += '<td>'+data["terminalListData"][i]["TERMINAL_ID"]+'</td>';
			htmlStr += '<td>'+data["terminalListData"][i]["SHOP_NAME"]+'</td>';
			htmlStr += '<td>'+data["terminalListData"][i]["VERNDOR_NAME"]+'</td>';
			htmlStr += '<td>'+data["terminalListData"][i]["CURRENT_VERSION"]+'</td>';
			
			if(data["terminalListData"][i]["available"]=="1"){
				htmlStr += '<td><span style="COLOR: #F60">有效</span></td>';
			}else{
				htmlStr += '<td><span style="COLOR: #228B22">无效</span></td>';
			}
			
			if(data["terminalListData"][i]["TOTAL"]==""){
				htmlStr += '<td><span style="COLOR: #F60">离线</span></td>';
			}else{
				htmlStr += '<td><span style="COLOR: #228B22">在线</span></td>';
			}
			
			htmlStr += '</tr>';

		}


		$("#terminalList").html(htmlStr);

//		setPage(pageIndex,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_terminal");
        $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 changePageCallback:function(pageSize,page){  
				 getQueryTerminalList(page,pageSize,terminalId);
			 },
			 changePageSizeCallBack:function(pageSize){
				 getQueryTerminalList(1,pageSize,terminalId);
			 } 
	     }); 
	}else{
		 base.tips_error(data["message"]);
 	 } 
	  base.cancelLoading();	
   }


/**
 * 重置参数
 */
function resetSearchParams(){

	terminalId="";
	$("#terminalId").val("");
	
	
	
}

/**
 * 搜索终端
 */
function searchTerminal(){
	
	tips_index=0;
	
	terminalId=$("#terminalId").val();
	
	getQueryTerminalList(1,10,terminalId);
	
}








/**
 * 错误提示
 * @param textStatus
 */
function requestError(textStatus){
	
	 
	 base.tips_error("与服务器连接失败!");
	 
	 base.cancelLoading();
	 
	
}

function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
}

//暴露方法
//window.$ddf_terminal={};
//window.$ddf_terminal.loadTerminalList=loadTerminalList;
exports.getQueryTerminalList=getQueryTerminalList;
exports.getQueryTerminalListCallBack=getQueryTerminalListCallBack;
//window.$ddf_terminal.getQueryTerminalList=getQueryTerminalList;
//window.$ddf_terminal.getQueryTerminalListCallBack=getQueryTerminalListCallBack;
exports.resetSearchParams=resetSearchParams;
exports.searchTerminal=searchTerminal;

});
//})();